<%--
  DO COMPUTING (CONTROLLER)
  User: PING
  Date: 2022/9/7
  Time: 9:50
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"
        import="com.javaweb.common.DBUtil"
        import="com.javaweb.common.StringTool"
        import="com.javaweb.common.DispatcherTool"%>

<html>
<meta charset="UTF-8">
<head>
    <title></title>
</head>
<body>
    <%
        // process the request from login UI
        // in default 8859-1
        request.setCharacterEncoding("utf-8");
        // read data from the body of request in UTF-8
        String name = request.getParameter("name") ;
        String pwd = request.getParameter("pwd") ;

        if (StringTool.isEmpty(name) || StringTool.isEmpty(pwd)) {
            response.sendRedirect("login.jsp?info=" + StringTool.URLEncodeInUTF("名字或密码为空！"));
            //DispatcherTool.responseWithInfo(response, "login.jsp", "名字或密码为空！");
            return ;
        }
        if (! DBUtil.existedUser(name, pwd)) {
            DispatcherTool.responseWithInfo(response, "login.jsp", "密码不正确！");
            return ;
        }
        // forward(转发)
        request.getRequestDispatcher("show.jsp?user=" + StringTool.URLEncodeInUTF(name))
                          .forward(request, response);


    %>

</body>
</html>
